package xaj.main;

import java.io.File;
import java.util.Collection;
import java.util.LinkedList;

public class Loadder {
	/**
	 * Load all names of sources files in path (files .java, .aj, .sc)
	 * @param path Source files path
	 * @return Collection with all source files names
	 */
	public static Collection<String> loadSourceRoots(String path) {
		Collection<String> sources = new LinkedList<String>();
		File file = new File(path);
		File[] files = file.listFiles();
		if (files == null) {
			throw new IllegalArgumentException("Sourceroot " + path
					+ " is not a directory");
		}
		for (int i = 0; i < files.length; i++) {
			if (files[i].isDirectory()) {
				sources.addAll(loadSourceRoots(files[i].getAbsolutePath()));				
			} else {
				String fileName = files[i].getAbsolutePath();
				if (fileName.endsWith(".java") || fileName.endsWith(".aj")
						|| fileName.endsWith(".sc")) {
					sources.add(fileName);
				}
			}
		}
		return sources;
	}
}
